package com.cosyhut.blocks.display;

import java.util.HashMap;

import com.jme.input.*;
import com.jme.input.action.*;
import com.jme.input.thirdperson.*;
import com.jme.renderer.*;
import com.jme.scene.*;


/**
 * 
 * @author timWorks
 * Feb 20, 2007
 * 
 * handles all input for the game
 *
 */
public class GInput {
    private InputHandler _input;

    private InputAction _forward;
    private InputAction _backword;
    private InputAction _leftard;
    private InputAction _rightward;
    
    private Camera _cam;
    private Node _current;
    
    private boolean _finished = false;
    
    public GInput(Camera cam, Node node) {
        this._cam = cam;
        this._current = node;
        this.init();
        this.initKeys();
    }
    
    private void init() {
        HashMap props = new HashMap();
        props.put(ChaseCamera.PROP_MAXDISTANCE, "1.5f");
        props.put(ChaseCamera.PROP_MINDISTANCE, "1");
        props.put(ChaseCamera.PROP_DAMPINGK, "12");
        props.put(ChaseCamera.PROP_SPRINGK, "36");
        //props.put(ThirdPersonMouseLook.PROP_MOUSEBUTTON_FOR_LOOKING, "false");
        props.put(ThirdPersonMouseLook.PROP_ENABLED, "false");

        ChaseCamera chaser = new ChaseCamera(this._cam, this._current, props);
        chaser.setStayBehindTarget(true);
        chaser.setLooking(true);
        chaser.setMaintainAzimuth(false);
        chaser.setForceAzimuthUpdate(true);
        chaser.setEnableSpring(true);
        
        this._forward = new KeyForwardAction(this._cam, 0.1f);
        chaser.addAction(this._forward, "forward", KeyInput.KEY_W, true);
        this._input = chaser;
    }
    
    public void update(float tpf) {
        InputSystem.update();
        this._input.update(tpf);
        if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit",
                false)) {
            this._finished = true;;
        }

    }
    
    private void initKeys() {
        KeyBindingManager.getKeyBindingManager().set("exit",
                KeyInput.KEY_ESCAPE);        
    }
    
    //--------------------------------------------------------------------------
    public boolean isFinished() {
        return this._finished;
    }
}
